__author__ = 'FJF'
# -*- coding:utf-8 -*-
import xlrd
import xlwt
from xlutils.copy import copy
import os

filenames = []
def getnames( ):
    filedir = 'F:\\test\\'
    filename = os.listdir( filedir )
    return filename

filenames = getnames( )

def rename( oldname, newmame ):
    os.rename( oldname, newmame )

def getname( oldname ):
    filepath = 'F:\\test\\' + oldname
    old_excel = xlrd.open_workbook( filepath )
    old_ws = old_excel.sheets( )[0]
    newname = old_ws.cell_value( 24, 3 )
    newname = 'F:\\test\\' + newname + '.xlsx'
    return newname
count = 0
for i in filenames:
    newname = getname( i )
    oldname = 'F:\\test\\' + i
    rename( oldname, newname )
    count = count + 1
    percent = count / len( filenames ) * 100
    print( i + "->" + newname + "         " + str( percent ) + "%" )
